package com.qf.controller;

import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.Random;

@RestController
public class AddController {
    HashMap<Integer, String> map = new HashMap<>();

    @RequestMapping("/add")
    public HashMap<Integer,String> add(String username){
        map.put(0,"zhaoliu");
        map.put(1,"xiaofeng");
        map.put(2,"xiaoming");
        map.put(3,"xiaoli");
        if (map.size()==0||!(map.containsValue(username))&&username!=null){
            map.put(map.size(), username );
            System.out.println("传入成功");
        } else{
            System.out.println("传入数据错误");
        }
        return map;
    }
    @RequestMapping("/get")
    public String get(){
        Random random = new Random();
        int index = random.nextInt(map.size()-1);
        return map.get(index);
    }
}
